<?php

	$userID = $_SESSION['userId'];
	
	error_reporting(0);
	$delMsg = '';
	$delMsg = $_GET['delMsg'];
	
	$con = mysql_connect("localhost", "group5", "group5");
    if(!$con)
    {
		echo "Connection failed!";
        exit;
    }
	
	
	
	mysql_select_db("group5");
	echo "<h3>Workshops you're currently registered for:</h3>";
	
	echo "<form method = 'post' action = 'delete.php'><table class='table table-condensed table-striped table-bordered'><tbody>
		<tbody>
			<tr>
				<th>Workshop Title</th>
				<th>Meeting Date</th>
				<th>Meeting Time</th>
				<th>Workshop Description</th>
				<th>Building</th>
				<th>Room</th>
				<th>Instructor</th>
				<th>Capacity</th>
				<th>Current Enrolled</th>
				<th>Select</th>
			</tr>";
	
		
		
	
	$table = mysql_query("select * from WORKSHOP_SESSIONS as WS JOIN USER_WORKSHOP as UW
	ON WS.workshopSessionId=UW.workshopSessionId JOIN USERS as U ON UW.userId=U.userId 
	where U.userId = $userID", $con);
	
	
	
	while($getRow = mysql_fetch_row($table))
	{
	//workshopSessionId = 0;
	//meetingTime = 1;
	//meetingDay = 2
	//workshopId = 3
	//roomId = 4
	//instructorId = 5
	$workshopSessionId = $getRow[0];
	$meetingTime = $getRow[1];
	$meetingDay = $getRow[2];
	$workshopId = $getRow[3];
	$roomID = $getRow[4];
	$instructorId = $getRow[5];

	//Data about the name and description of a Workshop
	$titleInfo = mysql_query("select * from WORKSHOP where workshopId = $workshopId", $con);
	$getTitle = mysql_fetch_row($titleInfo);
	
	$title = $getTitle[1];
	$descrip = $getTitle[2];
	
	//Data about the room and building number of a workshop.
	$roomInfo = mysql_query("select * from ROOM where roomId = $roomID;", $con);
	$getRoom = mysql_fetch_row($roomInfo);
	
	$roomCap = $getRoom[1];
	$roomNum = $getRoom[2];
	$building = $getRoom[3];
	
	
	//Data about the building
	$bldgInfo = mysql_query("select * from BUILDING where bldgID = $building", $con);
	$getBldg = mysql_fetch_row($bldgInfo);
	
	$bldgName = $getBldg[1];
	
	//Data about the name of the instructor
	$instructInfo = mysql_query("select firstName,lastName from USERS where userId = $instructorId");
	$getInstruct = mysql_fetch_row($instructInfo);
	
	$fName = $getInstruct[0];
	$lName = $getInstruct[1];
	$instrurctName = $fName . " " . $lName;
	
	$capInfo = mysql_query("select count(*) from WORKSHOP_SESSIONS as WS JOIN USER_WORKSHOP as UW ON WS.workshopSessionId=UW.workshopSessionId JOIN ROOM as R ON WS.roomId=R.roomId where R.roomId = $roomID", $con);
	$getCap = mysql_fetch_row($capInfo);
		
	$curEnroll = $getCap[0];
		
	echo "<tr>
		<td>$title</td>
		<td>$descrip</td>
		<td>$meetingTime</td>
		<td>$meetingDay</td>
		<td>$bldgName</td>
		<td>$roomNum</td>
		<td>$instrurctName</td>
		<td>$roomCap</td>
		<td>$curEnroll</td>
		
		<td><input type = 'radio' name='select' id='select' value ='$workshopSessionId'></td>
		</tr>";
	}
		
	echo "</tbody></table>";
	
	echo "<input type='submit' value = 'Delete Selected Session'></form>";
?>
<p id='delMsg'><?php echo $delMsg; ?></p>
